import request from '../../utils/request'
import {download} from '../../utils/commons'
import constants from '../../utils/Constants'

/**
 * 分页查询结算单列表
 * @param status
 * @param stateno
 * @param cstId
 * @param minamount
 * @param maxamount
 * @param creator
 * @param beginTime
 * @param endTime
 * @param page
 * @returns {Promise.<void>}
 */
export async function getStatementsList({status, stateno, customerno, minamount,maxamount, creator, beginTime, endTime, page}) {

    return request(apiPath.mc + "/api/statements", {
        method: 'get',
        data: { status, stateno, customerno, minamount,maxamount, creator, beginTime, endTime, page: page.page, size: page.size}
    });
}

/**
 * 分页查询结算单列表
 * @param status
 * @param stateno
 * @param cstId
 * @param minamount
 * @param maxamount
 * @param creator
 * @param beginTime
 * @param endTime
 * @param page
 * @returns {Promise.<void>}
 */
export async function getCstIdStatementsList({status, stateno, cstId, minamount,maxamount, creator, beginTime, endTime, page}) {
    return request(apiPath.mc + "/api/statements/"+ cstId, {
        method: 'get',
        data: { status, stateno, cstId, minamount,maxamount, creator, beginTime, endTime, page: page.page, size: page.size}
    });
}


/**
 * 结算单审批
 * @param id
 * @param approvalresult
 * @param approvalmemo
 * @returns {Promise.<void>}
 */
export async function doApproval({id, approvalresult, approvalmemo}) {
    return request(apiPath.mc + "/api/statement/" + id +"/approval", {
        method: 'post',
        data: { approvalresult, approvalmemo, appCode : constants.APPCODE}
    });
}


/**
 * 结算单付款
 * @param id
 * @param stateid
 * @param filename
 * @param memo
 * @returns {Promise.<void>}
 */
export async function pay({id, stateid, filename, status, url, memo}) {
    return request(apiPath.mc + "/api/statement/" + id +"/pay", {
        method: 'post',
        data: { stateid, filename, status, url, memo}
    });
}

/**
 * 更新结算单
 * @param id
 * @param status
 */
export async function updateStatus({id, status}) {
    return request(apiPath.mc + "/api/statement/" + id +"/status", {
        method: 'post',
        data: { id, status}
    });
}

/**
 * 结算单信息查询
 * @param id
 * @returns {Promise.<void>}
 */
export async function getStatementById({id}) {
    return request(apiPath.mc + "/api/statement/"+ id, {
        method: 'get'
    });
}


/**
 * 结算单付款信息查询
 * @param id
 * @returns {Promise.<void>}
 */
export async function getPayById({id}) {
    return request(apiPath.mc + "/api/statement/" + id + "/pay", {
        method: 'get',
    });
}

/**
 * 分页结算单审核信息查询
 * @param id
 * @returns {Promise.<void>}
 */
export async function getApprovalById({id, page}) {
    return request(apiPath.mc + "/api/statement/" + id + "/approval", {
        method: 'get',
        data: {page: page.page, size: page.size}
    });
}

/**
 * 增加结算单
 * @param type
 * @param transferamount
 * @param unpayamount
 * @param filename
 * @param url
 * @param accname
 * @param accopenbank
 * @param accno
 * @param payman
 * @param paytime
 * @returns {Promise.<void>}
 */
export async function addStatement({type, transferamount, unpayamount, filename, url, accname, accopenbank, accno, cstid, orderIds, historyAmtIds, forexIds, depositids, payman,memo, orderChargesIds}) {
    return request(apiPath.mc + "/api/statement/" + type , {
        method: 'post',
        data: {type, transferamount, unpayamount, filename, url, accname, accopenbank, accno, cstid, orderIds, historyAmtIds, forexIds, depositids, payman,memo, orderChargesIds}
    });
}

/**
 * 增加结算单-市场采购
 * @param type
 * @param transferamount
 * @param unpayamount
 * @param filename
 * @param url
 * @param accname
 * @param accopenbank
 * @param accno
 * @param payman
 * @param paytime
 * @returns {Promise.<void>}
 */
export async function createMpStatement({type, transferamount, unpayamount, filename, url, accname, accopenbank, accno, cstid, payman,memo, orderIds, historyAmtIds, forexIds, depositids, orderChargesIds, statementMpStr}) {
    return request(apiPath.mc + "/api/statementMp/" + type , {
        method: 'post',
        data: ({type, transferamount, unpayamount, filename, url, accname, accopenbank, accno, cstid, payman,memo, orderIds, historyAmtIds, forexIds, depositids, orderChargesIds,statementMpStr})
    });
}

/**
 * 导出excel
 * @param orderId
 * @returns {Promise.<void>}
 */
export async function exportStatement({id}) {
    let url =  apiPath.mc + "/api/exportStatement";
    download(url, {statementId: id, filename: '付款申请表'});

}

/**
 * 导出excel
 * @param orderId
 * @returns {Promise.<void>}
 */
export async function exportStatementList({status,stateno, customerno, minamount, maxamount, beginTime, endTime }) {
    let url =  apiPath.mc + "/api/report/statements/export";
    download(url, {status,stateno, customerno, minamount, maxamount, beginTime, endTime , filename: '付款记录信息表'});

}
